package com.xugou.controller;

import com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer;
import com.xugou.pojo.User;
import com.xugou.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author xugou
 * @date 2021/11/12  22:15
 */
@Controller
@RequestMapping("/user")
public class UserController {
    //controller来调用service层
    @Autowired
    @Qualifier("UserServiceImpl")
    private UserService userService;

    //登录
    @RequestMapping("/login")
    public String login(User user, Model model){
        User checkUser = userService.checkLogin(user.getUsername(), user.getPassword());
        if (checkUser!=null){
            return "welcome";
        }else {
            return "fail";
        }
    }
    //注册
    @RequestMapping("/regist")
    public String regist(User user, Model model){
        boolean flag = userService.Regist(user);
        if (flag==true){
            return "welcome";
        }else {
            return "fail";
        }
    }
}
